package com.ruoyi.app.service.impl;

import com.ruoyi.app.aspect.PermissionAspect;
import com.ruoyi.app.domain.OrderInfo;
import com.ruoyi.app.domain.OrderInfoExample;
import com.ruoyi.app.mapper.OrderInfoMapper;
import com.ruoyi.app.service.OrderService;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.framework.web.domain.AjaxResult;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/*
@description:订单服务
@ClassName OrderServiceImpl
@author chen
@create 2025-03-18 21:08
@Version 1.0
*/
@Slf4j
@Service
@AllArgsConstructor
public class OrderServiceImpl implements OrderService
{

    final OrderInfoMapper orderInfoMapper;

    /*
     * @==============History===============<br/>
     * @Description //   查询订单列表
     * @Date 2025-3-18 21:12
     * @Author < a href="15991488967@163.com">chen</ a>
     * @return java.util.List<com.ruoyi.app.domain.OrderInfo>
     */
    @Override
    public List<OrderInfo> getOrderList(Map<String, Object> params)
    {
        return orderInfoMapper.getOrderList(params);
    }

    /*
     * @==============History===============<br/>
     * @Description //   小程序删除订单（取消订单）
     * @Date 2025-3-18 21:42
     * @Author < a href="15991488967@163.com">chen</ a>
     * @return com.ruoyi.framework.web.domain.AjaxResult
     */
    @Override
    public AjaxResult deleteOrderInfo(Long id)
    {
        OrderInfoExample orderInfoExample = new OrderInfoExample();
        orderInfoExample.createCriteria()
                .andCreateIdEqualTo(PermissionAspect.loginUser.get().getId())
                .andIdEqualTo(id);
        return orderInfoMapper.deleteByExample(orderInfoExample) > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    /*
     * @==============History===============<br/>
     * @Description //   删除订单
     * @Date 2025-3-18 21:52
     * @Author < a href="15991488967@163.com">chen</ a>
     * @return com.ruoyi.framework.web.domain.AjaxResult
     */
    @Override
    public AjaxResult deleteByPrimaryKey(Long id)
    {
        return orderInfoMapper.deleteByPrimaryKey(id) > 0 ? AjaxResult.success() : AjaxResult.error();
    }
}

